package cn.vplay.controllers;

import cn.vplay.beans.Product;
import cn.vplay.services.ProductService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping("/list")
    @ResponseBody
    public String getAllProducts() {
        List<Product> prods = productService.getAllProducts();
        return new Gson().toJson(prods);
    }
}
